package com.by.ai.controller;

import com.by.ai.dto.LogAnalysisRequest;
import com.by.ai.dto.LogAnalysisResponse;
import com.by.ai.service.LogAnalysisService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author lby
 * @description
 * @date 2025/8/5 1:12
 */

@Tag(name = "日志分析智能体", description = "基于AI的日志分析服务")
@RestController
@RequestMapping("/api/ai/log-analysis")
public class LogAnalysisController {

    @Autowired
    LogAnalysisService logAnalysisService;

    @Operation(summary = "综合日志分析")
    @PostMapping("/analyze")
    public LogAnalysisResponse analyzeLog(@RequestBody LogAnalysisRequest request) {
        return logAnalysisService.analyzeLog(request);
    }

    @Operation(summary = "请求量分析")
    @GetMapping("/request-count")
    public Object analyzeRequestCount(
            @RequestParam LocalDateTime startTime,
            @RequestParam LocalDateTime endTime,
            @RequestParam(required = false) String serviceName) {
        return logAnalysisService.analyzeRequestCount(startTime, endTime, serviceName);
    }

    @Operation(summary = "流量分析")
    @GetMapping("/traffic")
    public Object analyzeTraffic(
            @RequestParam LocalDateTime startTime,
            @RequestParam LocalDateTime endTime,
            @RequestParam(required = false) String serviceName) {
        return logAnalysisService.analyzeTraffic(startTime, endTime, serviceName);
    }

    @Operation(summary = "错误追踪分析")
    @GetMapping("/errors")
    public Object analyzeErrors(
            @RequestParam LocalDateTime startTime,
            @RequestParam LocalDateTime endTime,
            @RequestParam(required = false) String serviceName) {
        return logAnalysisService.analyzeErrors(startTime, endTime, serviceName);
    }

    @Operation(summary = "异常检测")
    @GetMapping("/anomalies")
    public List<String> detectAnomalies(
            @RequestParam LocalDateTime startTime,
            @RequestParam LocalDateTime endTime) {
        return logAnalysisService.detectAnomalies(startTime, endTime);
    }
}